/**
 * TODO: provide description with examples.
 *
 * @author Andrey Anisimov <hercules@inbox.ru>
 */

import core.util.validation.NonEmptyValidator;
import core.util.validation.ValidationError;

class EmailValidator extends NonEmptyValidator {

	/**
	 * @throws ValidationError The validation fails.
	 */
	this.validate = function() {
		super.validate();
		var email = this.getTarget().getText();
		if (!email.match(/^[_A-Za-z0-9-]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)+$/)) {
			throw new ValidationError(this, 'The email address is invalid.');
		}
	}
}